<template>
  <div v-drag>
    <div class="mask" @click="closePopup(false)"></div>
    <div class="edit_box" v-loading="loading">
      <div class="box_head">
        <p>退货订单审核</p>
        <i @click="closePopup(false)"></i>
      </div>
      <div class="box_body">
        <div>
          <div>
            <div
              v-for="(item, index) in list"
              :key="index"
              class="input-box g-mb-10"
              id="link"
            >

            <div class="flex_center">
              <div class="name">
              <el-input v-model="item.productName" disabled></el-input>
                </div>
              <div class="num" @click="getIndex(index,$event)">
               <template>
                      <el-input-number v-model="item.payableNumber" @change="handleChange" :min="0" :max="100" ></el-input-number>
              </template>
              </div>
            </div>
            </div>
          </div>
        </div>

      </div>
      <div class="box_foot">
        <span @click="closePopup(false)">取消</span>
        <span @click="confirmEdit">确定</span>
      </div>
    </div>
  </div>
</template>

<script>
import { returnCheck,returnDetail } from "@/api/data/user/productReturn";

export default {
  props: ["userId", "orderNo"],
  data() {
    return {
      loading: false,
      list: [],
      num: 1,
      index:'',
      proNum:[],
    };
  },
  mounted() {
    this.getCheckData();
  },
  methods: {
    getCheckData() {
      returnDetail(this.orderNo).then((res) => {
        this.list = res ? res : [];
        var proNum = [];
        res.forEach((item) => {
          let obj = {productId:item.productId,payableNumber:item.payableNumber}
          proNum.push(obj)
        })
        this.proNum = proNum
      });
    },

    //更改审核的数量
    getIndex(index,e) {
      this.proNum[index].payableNumber = this.num;
    },
    handleChange(val) {
      this.num = val;
    },

    closePopup(refresh) {
      this.$emit("listenToChild", refresh);
    },

    //把当前更改的提交
    confirmEdit() {
       this.loading = true;
       let data = {
         details:this.proNum,
         returnNo:this.orderNo,
         userId:this.userId
       }
      returnCheck(data)
        .then((res) => {
          this.$message.success({
            message:"清点完成",
            duration:1500
          });
          this.closePopup(true);
          this.loading = false;
        })
        .catch((e) => {
          this.loading = false;
        });
    },

  },
};
</script>

<style scoped>
.input_box {
  display: flex;
  align-items: center;
  position: relative;
  overflow: hidden;
  /*width: 400px;*/
}
.flex_center .name {
  width:50%;
  display: inline-block;
}

.flex_center .num {
  width:22%;
  display: inline-block;
  margin-left:5px;
  padding-left:2px;

}

.flex_center {
  width:100%;
  justify-content: center;
  flex-wrap: nowrap;
}

.line .link-input {
  line-height: 36px;
  border-radius: 4px;
  outline: none;
}

* {
  box-sizing: border-box;
}

.g-mb-10 {
  margin-bottom: 10px;
}

.g-ml-15 {
  margin-left: 15px;
}

a {
  text-decoration: none;
}

.link-txt {
  margin-right: 12px;
  width: 15px;
  float: left;
}

.link-input {
  width: 250px;
  height: 36px;
  background-color: #ffffff;
  border-radius: 2px;
  border: solid 1px #dcdcdc;
  padding-left: 15px;
  float: left;
  display: block;
  font-size: 14px;
  padding-right: 35px;
}

.common_btn {
  font-size: 24px;
  cursor: pointer;
  color: #6687f9;
  margin-right: 5px;
}

.delSingle {
  position: absolute;
  top: 10px;
  right: 38px;
  cursor: pointer;
  font-size: 22px;
  color: #e40000;
}

.num_box {
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  overflow: hidden;
  margin-left: 30px;
}

.minus_btn,
.plus_btn {
  width: 34px;
  display: inline-block;
  height: 34px;
  line-height: 34px;
  text-align: center;
  cursor: pointer;
}

.minus_btn i,
.plus_btn i {
  color: #6687f9;
}

.minus_btn {
  border-right: 1px solid #dcdfe6;
}

.plus_btn {
  border-left: 1px solid #dcdfe6;
}

.lose {
  color: #dcdfe6 !important;
}

.num_show {
  max-width: 80px;
  min-width: 40px;
  line-height: 34px;
  text-align: center;
  border: none;
  outline: none;
}
.specail_error {
  padding-left: 0;
  margin-top: 30px;
}
</style>
